<?php
    function textArea($label, $field, $attr = "", $max_length = 100, $style = "")
	{
		echo "<label for='".$field."'>".$label."</label>";
        echo "<textarea name='".$field."' maxlength='".$max_length."' id='".$field."' ".$attr." style='".$style."'></textarea>";
	}
    
    function textAreaFor($label, $field, $value, $attr = "", $max_length = 100, $style = "")
	{
		echo "<label for='".$field."'>".$label."</label>";
        echo "<textarea name='".$field."' maxlength='".$max_length."' id='".$field."' ".$attr." style='".$style."'>".$value."</textarea>";
	}


    function textBox($label, $field, $attr = "", $max_length = 100, $style = "")
	{
		echo "<label for='".$field."'>".$label."</label><input type='text' name='".$field."' maxlength='".$max_length."' id='".$field."' ".$attr." style='".$style."'/>";
	}

    function textBoxFor($label, $field, $value, $attr = "", $max_length = 100, $style = "")
	{
		echo "<label for='".$field."'>".$label."</label><input type='text' name='".$field."' maxlength='".$max_length."' id='".$field."' ".$attr." value='".$value."' style='".$style."'/>";
	}
	
	function textBoxForNoLabel($field, $attr = "", $max_length = 100, $style = "")
	{
		echo "<input type='text' name='".$field."' maxlength='".$max_length."' class='complement-".$field."' style='".$style."'/>";
	}

	function selectBoxFor($label, $field, $object, $attr = "", $style = "")
	{
		echo "<label for='".$field."'>".$label."</label>";
	

		echo "<select id='".$field."' name='".$field."' style='".$style."'>";
		
		$result = $object->listAll();
        
        echo "<option value='0'></option>";
        
		while($item = mysql_fetch_object($result))
		{
			echo "<option value='".$item->id."'>".$item->name."</option>";
		}
		
		echo "</select>";
	}
    
    function selectBox($label, $field, $string, $attr = "", $style = "")
	{
		echo "<label for='".$field."'>".$label."</label>";
	

		echo "<select id='".$field."' name='".$field."' style='".$style."'>";
        $itens = explode(",", $string);
		for($i = 0; $i < count($itens);)
        {
            echo "<option value='".$itens[$i]."'>".$itens[$i]."</option>";
            $i++;
        }		
		
		echo "</select>";
	}
	
    function selectBoxValue($label, $field, $string, $value, $attr = "", $style = "")
	{
		echo "<label for='".$field."'>".$label."</label>";
	

		echo "<select id='".$field."' name='".$field."' style='".$style."'>";
        $itens = explode(",", $string);
        $values = explode(",", $value);
		for($i = 0; $i < count($itens);)
        {
            echo "<option value='".$values[$i]."'>".$itens[$i]."</option>";
            $i++;
        }		
		
		echo "</select>";
	}
    
    function selectBoxSelected($label, $field, $object, $selected, $attr = "", $style = "")
	{
		echo "<label for='".$field."'>".$label."</label>";
	

		echo "<select id='".$field."' name='".$field."' style='".$style."'>";
		
		$result = $object->listAll();
        echo "<option value='0'></option>";
		while($item = mysql_fetch_object($result))
		{
            if($selected == $item->id)
                echo "<option value='".$item->id."' selected>".$item->name."</option>";
            else
                echo "<option value='".$item->id."'>".$item->name."</option>";
             
		}
		
		echo "</select>";
	}
    
	function radio($label, $name, $text, $fields, $attr = "")
	{
		$text = explode(",",$text);
		$fields = explode(",",$fields);
		
		$size = count($text);
		
		echo "<label>".$label."</label>";
		echo "<div class='radiofield'>";
		for($i = 0; $i < $size; $i++)
		{
			if($i == 0)
				echo "<input type='radio' name='".$name."' value='".$fields[$i]."' checked/>".$text[$i];
			else
				echo "<input type='radio' name='".$name."' value='".$fields[$i]."'/>".$text[$i];
		}
		echo "</div>";
	}
    
    function radioFor($label, $name, $text, $fields, $selected, $attr = "")
	{
		$text = explode(",",$text);
		$fields = explode(",",$fields);
		
		$size = count($text);
		
		echo "<label>".$label."</label>";
		echo "<div class='radiofield'>";
		for($i = 0; $i < $size; $i++)
		{
			if($selected == $fields[$i])
				echo "<input type='radio' name='".$name."' value='".$fields[$i]."' checked/>".$text[$i];
			else
				echo "<input type='radio' name='".$name."' value='".$fields[$i]."'/>".$text[$i];
		}
		echo "</div>";
	}
    
    function checkBoxFor($label, $name, $selected = 0, $attr = "")
    {		
		echo "<label>";
	    
        if($selected == 1)
            echo "<input type='checkbox' name='".$name."' checked/>";
        else
            echo "<input type='checkbox' name='".$name."' />";
            
        echo $label;
        echo "</label>";
		
    }
?>